home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / gcl-1.000 / gcl-1 / gcl-1.0 / cmpnew / cmpspecial.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1994-05-07  |  5.6 KB  |  154 lines

  1. ;;; CMPSPECIAL  Miscellaneous special forms.
  2. ;;;
  3. ;; Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
  4.  
  5. ;; This file is part of GNU Common Lisp, herein referred to as GCL
  6. ;;
  7. ;; GCL is free software; you can redistribute it and/or modify it under
  8. ;;  the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
  9. ;; the Free Software Foundation; either version 2, or (at your option)
  10. ;; any later version.
  11. ;; 
  12. ;; GCL is distributed in the hope that it will be useful, but WITHOUT
  13. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. ;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
  15. ;; License for more details.
  16. ;; 
  17. ;; You should have received a copy of the GNU Library General Public License 
  18. ;; along with GCL; see the file COPYING.  If not, write to the Free Software
  19. ;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22. (in-package 'compiler)
  23.  
  24. (si:putprop 'quote 'c1quote 'c1special)
  25. (si:putprop 'function 'c1function 'c1special)
  26. (si:putprop 'function 'c2function 'c2)
  27. (si:putprop 'the 'c1the 'c1special)
  28. (si:putprop 'eval-when 'c1eval-when 'c1special)
  29. (si:putprop 'declare 'c1declare 'c1special)
  30. (si:putprop 'compiler-let 'c1compiler-let 'c1special)
  31. (si:putprop 'compiler-let 'c2compiler-let 'c2)
  32.  
  33. (defun c1quote (args)
  34.   (when (endp args) (too-few-args 'quote 1 0))
  35.   (unless (endp (cdr args)) (too-many-args 'quote 1 (length args)))
  36.   (c1constant-value (car args) t)
  37.   )
  38.  
  39. (defun c1eval-when (args)
  40.   (when (endp args) (too-few-args 'eval-when 1 0))
  41.   (dolist** (situation (car args) (c1nil))
  42.     (case situation
  43.           (eval (return-from c1eval-when (c1progn (cdr args))))
  44.           ((load compile))
  45.           (otherwise
  46.            (cmperr "The situation ~s is illegal." situation))))
  47.   )
  48.  
  49. (defun c1declare (args)
  50.   (cmperr "The declaration ~s was found in a bad place." (cons 'declare args))
  51.   )
  52.  
  53. (defun c1the (args &aux info form type)
  54.   (when (or (endp args) (endp (cdr args)))
  55.         (too-few-args 'the 2 (length args)))
  56.   (unless (endp (cddr args))
  57.           (too-many-args 'the 2 (length args)))
  58.   (setq form (c1expr (cadr args)))
  59.   (setq info (copy-info (cadr form)))
  60.   (setq type (type-and (type-filter (car args)) (info-type info)))
  61.   (when (null type)
  62.         (cmpwarn "Type mismatch was found in ~s." (cons 'the args)))
  63.   (setf (info-type info) type)
  64.   (list* (car form) info (cddr form))
  65.   )
  66.  
  67. (defun c1compiler-let (args &aux (symbols nil) (values nil))
  68.   (when (endp args) (too-few-args 'compiler-let 1 0))
  69.   (dolist** (spec (car args))
  70.     (cond ((consp spec)
  71.            (cmpck (not (and (symbolp (car spec))
  72.                             (or (endp (cdr spec))
  73.                                 (endp (cddr spec)))))
  74.                   "The variable binding ~s is illegal." spec)
  75.            (push (car spec) symbols)
  76.            (push (if (endp (cdr spec)) nil (eval (cadr spec))) values))
  77.           ((symbolp spec)
  78.            (push spec symbols)
  79.            (push nil values))
  80.           (t (cmperr "The variable binding ~s is illegal." spec))))
  81.   (setq symbols (reverse symbols))
  82.   (setq values (reverse values))
  83.   (setq args (progv symbols values (c1progn (cdr args))))
  84.   (list 'compiler-let (cadr args) symbols values args)
  85.   )
  86.  
  87. (defun c2compiler-let (symbols values body)
  88.   (progv symbols values (c2expr body)))
  89.  
  90. (defun c1function (args &aux fd)
  91.   (when (endp args) (too-few-args 'function 1 0))
  92.   (unless (endp (cdr args)) (too-many-args 'function 1 (length args)))
  93.   (let ((fun (car args)))
  94.        (cond ((symbolp fun)
  95.               (cond ((and (setq fd (c1local-closure fun))
  96.                           (eq (car fd) 'call-local))
  97.                      (list 'function *info* fd))
  98.                     (t (let ((info (make-info
  99.                                     :sp-change
  100.                                     (null (get fun 'no-sp-change)))))
  101.                             (list 'function info (list 'call-global info fun))
  102.                             ))))
  103.              ((and (consp fun) (eq (car fun) 'lambda))
  104.               (cmpck (endp (cdr fun))
  105.                      "The lambda expression ~s is illegal." fun)
  106.               (let ((*vars* (cons 'cb *vars*))
  107.                     (*funs* (cons 'cb *funs*))
  108.                     (*blocks* (cons 'cb *blocks*))
  109.                     (*tags* (cons 'cb *tags*)))
  110.                    (setq fun (c1lambda-expr (cdr fun)))
  111.                    (list 'function (cadr fun) fun)))
  112.              (t (cmperr "The function ~s is illegal." fun))))
  113.   )
  114.  
  115. (defun c2function (funob)
  116.   (case (car funob)
  117.         (call-global
  118.          (unwind-exit (list 'symbol-function (add-symbol (caddr funob)))))
  119.         (call-local
  120.          (if (cadddr funob)
  121.              (unwind-exit (list 'ccb-vs (fun-ref-ccb (caddr funob))))
  122.              (unwind-exit (list 'vs* (fun-ref (caddr funob))))))
  123.         (t
  124.          ;;; Lambda closure.
  125.          (let ((fun (make-fun :name 'closure :cfun (next-cfun))))
  126.               (push (list 'closure (if (null *clink*) nil (cons 0 0))
  127.                           *ccb-vs* fun funob)
  128.                     *local-funs*)
  129.               (push fun *closures*)
  130.           (cond (*clink*
  131.              (unwind-exit (list 'make-cclosure (fun-cfun fun) *clink*)))
  132.             (t (push-data-incf nil)
  133.                (add-init `(si::setvv ,*next-vv*
  134.                          (si::mc nil ,(add-address  "&LC"
  135.                                     (fun-cfun fun))))
  136.                  t) 
  137.                (unwind-exit (list 'vv *next-vv*)))))
  138.              ))
  139.   )
  140.  
  141. (si:putprop 'symbol-function 'wt-symbol-function 'wt-loc)
  142. (si:putprop 'make-cclosure 'wt-make-cclosure 'wt-loc)
  143.  
  144. (defun wt-symbol-function (vv)
  145.        (if *safe-compile*
  146.            (wt "symbol_function(VV[" vv "])")
  147.            (wt "(VV[" vv "]->s.s_gfdef)")))
  148.  
  149. (defun wt-make-cclosure (cfun clink)
  150.        (wt-nl "make_cclosure_new(LC" cfun ",Cnil,")
  151.        (wt-clink clink)
  152.        (wt ",Cdata)"))
  153.  
  154.